#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

class Solution {
public:
    int maxProfit(vector<int> &prices) {
	int maxP = 0;
	if (prices.size() <= 1) return maxP;

	int curMin = 0, curMax = 0;
        for (int i = 1; i < prices.size(); i++) {
	    if (prices[curMin] > prices[i]) {curMin = i;curMax = i;}
	    if (prices[curMax] < prices[i]) curMax = i;
	    if (maxP < prices[curMax] - prices[curMin]) {
		maxP = prices[curMax] - prices[curMin];
	    }
	}
	cout << maxP << endl;
	return maxP;
    }
};


int main(int argc, char **argv)
{
    Solution mySolution;
    vector<int> prices;
    prices.push_back(1);
    prices.push_back(2);
    mySolution.maxProfit(prices);
}
